#include "Framework/Prerequisites.h"

#include "Math/Vector2.h"
#include "Math/Matrix4.h"

namespace tyro
{
	namespace Geometry
	{
		class Frustum
		{
		public:

			Frustum();
			~Frustum();

			void Update( void ) const;

			tyro::FLOAT_32 GetNearVal() const { return nearVal; }
			void SetNearVal(tyro::FLOAT_32 val) { nearVal = val; }

			tyro::FLOAT_32 GetFarVal() const { return farVal; }
			void SetFarVal(tyro::FLOAT_32 val) { farVal = val; }

			tyro::FLOAT_32 GetLeft() const { return left; }
			void SetLeft(tyro::FLOAT_32 val) { left = val; }

			tyro::FLOAT_32 GetRight() const { return right; }
			void SetRight(tyro::FLOAT_32 val) { right = val; }

			tyro::FLOAT_32 GetBottom() const { return bottom; }
			void SetBottom(tyro::FLOAT_32 val) { bottom = val; }

			tyro::FLOAT_32 GetTop() const { return top; }
			void SetTop(tyro::FLOAT_32 val) { top = val; }

			tyro::ProjectionType GetProjectionType() const { return projectionType; }
			void SetProjectionType(tyro::ProjectionType val) { projectionType = val; }

			tyro::FLOAT_32 GetAspectRatio() const { return aspectRatio; }
			void SetAspectRatio(tyro::FLOAT_32 val) { aspectRatio = val; }

			Math::Matrix4f GetProjectionMatrix() const;

			void CalculateExtents(void) const;
			void CalculateProjection( void ) const;
			bool IsFrustrumDirty() const;
		protected:

			

		private:

			// The inverted z coordinate of the near clipping plane.
			FLOAT_32 nearVal;
			
			// The inverted z coordinate of the far clipping plane.
			FLOAT_32 farVal;
			
			mutable FLOAT_32 left, right, bottom, top;

			Math::Radianf FOVy;

			FLOAT_32 aspectRatio;
			
			FLOAT_32 focalLength;

			Math::Vector2f frustumOffset;

			mutable Math::Matrix4f projectionMatrix;
			
			ProjectionType projectionType;

			mutable bool recalcFrustrum;
			
			mutable bool recalcFrustrumPlanes;

			mutable bool recalcView;


		};

		

	}
}